//
//  MYGCloudDiskPopManager.swift
//  MYDoctor
//
//  Created by Denny on 2024/3/11.
//

import UIKit

class MYGCloudDiskPopManager: NSObject {
    /**
     添加文件弹窗
     */
    static func showAddFileAlert(_ view:UIView,fid:Int = 0) {
        view.rootResponsder().popup.bottomSheet(with: true, bgColor: .black.withAlphaComponent(0.43)) {
            let actionSheet = Bundle.main.loadNibNamed("MYGCloudDiskAddFileSheet", owner: nil)?.first as! MYGCloudDiskAddFileSheet
            actionSheet.fid = fid
            actionSheet.tapCloseCompletion = {
                view.rootResponsder().popup.dismissPopup()
            }
            
            //共享
            actionSheet.tapShareCompletion = {
                view.rootResponsder().popup.dismissPopup()
                MYGCloudDiskPopManager.showShareFileAlert(view)
            }
            actionSheet.tapCreatFileCompletion = {
                view.rootResponsder().popup.dismissPopup()
                MYGCloudDiskPopManager.showCreatNewFileAlert(view,pid: "\(fid)")

            }
            actionSheet.frame = CGRect.init(x: 0, y: 0, width: screenWidth, height: 224 + bottomSafeheight)
            return actionSheet
        }
    }
    
  
    
    /**
     编辑文件夹弹窗
     */
    static func showEditFileAlert(_ view:UIView,model:MYCloudDiskContentModel) {
        view.rootResponsder().popup.bottomSheet(with: true, bgColor: .black.withAlphaComponent(0.43)) {
            let actionSheet = Bundle.main.loadNibNamed("MYGCloudDiskEditFileSheet", owner: nil)?.first as! MYGCloudDiskEditFileSheet
            actionSheet.fileModel = model
            actionSheet.tapCloseCompletion = {
                view.rootResponsder().popup.dismissPopup()
            }
            //重命名
            actionSheet.tapRenameCompletion = {
                view.rootResponsder().popup.dismissPopup()
                MYGCloudDiskPopManager.showRenameFileAlert(view, model: model,type: 2)
            }
            //分享
            actionSheet.tapShareCompletion = {
                view.rootResponsder().popup.dismissPopup()
                MYGCloudDiskPopManager.showShareAlert(view, model: model)
            }
            
            actionSheet.bindData(model)
            actionSheet.frame = CGRect.init(x: 0, y: 0, width: screenWidth, height: 194 + bottomSafeheight)
            return actionSheet
        }
    }
    /**
     编辑文件弹窗
     */
    static func showEditDocmentAlert(_ view:UIView,model:MYCloudDiskContentModel) {
        view.rootResponsder().popup.bottomSheet(with: true, bgColor: .black.withAlphaComponent(0.43)) {
            
            let actionSheet = Bundle.main.loadNibNamed("MYGCloudDiskDoucmentSheet", owner: nil)?.first as! MYGCloudDiskDoucmentSheet
            actionSheet.fileModel = model
//            actionSheet.tapCloseCompletion = {
//                view.rootResponsder().popup.dismissPopup()
//            }
            actionSheet.tapDismissCompletion = {
                view.rootResponsder().popup.dismissPopup()
            }
            //重命名
            actionSheet.tapRenameCompletion = {
                view.rootResponsder().popup.dismissPopup()
                MYGCloudDiskPopManager.showRenameFileAlert(view, model: model,type: 1)
            }
            //分享
            actionSheet.tapShareCompletion = {
                view.rootResponsder().popup.dismissPopup()
                MYGCloudDiskPopManager.showShareAlert(view, model: model)
            }
//            
            actionSheet.frame = CGRect.init(x: 0, y: 0, width: screenWidth, height: 50 + bottomSafeheight)
            return actionSheet
        }
    }
    
    
    /**
     重命名弹窗
     type:修改类型（默认1修改文件名称 传2修改文件夹名称）
     */
    static func showRenameFileAlert(_ view:UIView,model:MYCloudDiskContentModel,type:Int) {
         view.rootResponsder().popup.dialog(with: true, bgColor: .black.withAlphaComponent(0.43)) {
            let alert = Bundle.main.loadNibNamed("MYGCloudDiskRenameFileAlert", owner: nil)?.first as! MYGCloudDiskRenameFileAlert
             alert.frame = CGRect.init(x: 0, y: 0, width: screenWidth - 30, height: 210)
             alert.isRename = true
             alert.type = type
             alert.fileModel = model
             alert.tapSureCompletion = { obj in
                 view.rootResponsder().popup.dismissPopup()

             }
             alert.tapClosePageCompletion = {
                 view.rootResponsder().popup.dismissPopup()
                 
             }
             return alert
         }
    }
    
    /**
     新建文件夹弹窗
     */
    static func showCreatNewFileAlert(_ view:UIView,pid:String = "") {
        view.rootResponsder().popup.dialog(with: true, bgColor: .black.withAlphaComponent(0.43)) {
            let alert = Bundle.main.loadNibNamed("MYGCloudDiskRenameFileAlert", owner: nil)?.first as! MYGCloudDiskRenameFileAlert
            alert.titleLB.text = "文件夹名"
            alert.pid = pid
            alert.frame = CGRect.init(x: 0, y: 0, width: screenWidth - 30, height: 210)
            alert.tapSureCompletion = { obj in
                view.rootResponsder().popup.dismissPopup()

            }
            alert.tapClosePageCompletion = {
                view.rootResponsder().popup.dismissPopup()

            }
            return alert
        }
    }
    
    
    /**
     共享->新建文件夹弹窗
     */
    static func showShareCreatNewFileAlert(_ view:UIView,pid:String = "", compeltion:@escaping(()->Void)) {
        view.rootResponsder().popup.dialog(with: true, bgColor: .black.withAlphaComponent(0.43)) {
            let alert = Bundle.main.loadNibNamed("MYGCloudDiskRenameFileAlert", owner: nil)?.first as! MYGCloudDiskRenameFileAlert
            alert.titleLB.text = "文件夹名"
            alert.pid = pid
            alert.frame = CGRect.init(x: 0, y: 0, width: screenWidth - 30, height: 210)
            alert.tapSureCompletion = { obj in
                view.rootResponsder().popup.dismissPopup()
                compeltion()
            }
            alert.tapClosePageCompletion = {
                view.rootResponsder().popup.dismissPopup()

            }
            return alert
        }
    }
    
    /**
     添加共享文件夹弹窗
     pid:创建子文件夹时候需要
     */
    
    static func showShareFileAlert(_ view:UIView,pid:String = "0") {
        view.rootResponsder().popup.dialog(with: true, bgColor: .black.withAlphaComponent(0.43)) {
            let alert = Bundle.main.loadNibNamed("MYGCloudDiskRenameFileAlert", owner: nil)?.first as! MYGCloudDiskRenameFileAlert
            alert.titleLB.text = "共享文件夹名"
            alert.pid = pid
            alert.is_sharing = true
            alert.frame = CGRect.init(x: 0, y: 0, width: screenWidth - 30, height: 210)
            alert.tapSureCompletion = { obj in
                view.rootResponsder().popup.dismissPopup()
                MYGCloudDiskPopManager.showShareAddFile(view, model: obj)
        
            }
            alert.tapClosePageCompletion = {
                view.rootResponsder().popup.dismissPopup()

            }
            return alert
        }
    }
    
    /**
     共享:root添加图片。视频，文档
    
     */
    
    static func showShareAddFile(_ view: UIView,model:MYCloudDiskContentModel) {
        view.rootResponsder().popup.bottomSheet(with: false, bgColor: .black.withAlphaComponent(0.43)) {
            let actionSheet = MYGShareAddFileView.init(frame: UIScreen.main.bounds)
            actionSheet.farmerModel = model
            actionSheet.tapCloseCompletion = {
                view.rootResponsder().popup.dismissPopup()
            }
            actionSheet.tapNextCompletion = {
                view.rootResponsder().popup.dismissPopup()
                let vc = MYGCloudDiskCommonShareFileVC()
                vc.farmerModel = model
                view.rootResponsder().navigationController?.pushViewController(vc, animated: true)
            }

            actionSheet.frame = UIScreen.main.bounds
            return actionSheet
        }
    }
    
    /**
     分享弹窗
     */
    static func showShareAlert(_ view:UIView,model:MYCloudDiskContentModel) {
        view.rootResponsder().popup.bottomSheet(with: true, bgColor: .black.withAlphaComponent(0.43)) {
            let actionSheet = Bundle.main.loadNibNamed("MYGCloudDiskShareSheet", owner: nil)?.first as! MYGCloudDiskShareSheet
            actionSheet.model = model
            actionSheet.tapClosePageCompletion = {
                view.rootResponsder().popup.dismissPopup()
            }
            actionSheet.tapOpenCompletion = {
                view.rootResponsder().popup.dismissPopup()
                let vc = H5ViewController()
                vc.url = MYCloudDiskManager.shared.shareModel.link_open
                view.rootResponsder().navigationController?.pushViewController(vc, animated: true)
            }
            
            actionSheet.tapPickCodeCompletion = {
                view.rootResponsder().popup.dismissPopup()
                let vc = H5ViewController()
                vc.url = MYCloudDiskManager.shared.shareModel.link_code
                view.rootResponsder().navigationController?.pushViewController(vc, animated: true)
            }
            actionSheet.tapValidityPeriodCompletion = {
                MYGCloudDiskPopManager.showValidityPeriodAlert(actionSheet, model: model) { (index ,obj)in
                    actionSheet.time = index
                    actionSheet.titleModel = obj
                }
            }
            actionSheet.frame = CGRect.init(x: 0, y: 0, width: screenWidth, height: 226 + bottomSafeheight)
            return actionSheet
        }
    }
    
    /**
     设置有效期
     */
    static func showValidityPeriodAlert(_ view:UIView,model:MYCloudDiskContentModel,completion:@escaping((Int,MYCloudDiskValidityPeriodModel)->Void)) {
        view.rootResponsder().popup.bottomSheet(with: true, bgColor: .black.withAlphaComponent(0.43)) {
            let actionSheet = Bundle.main.loadNibNamed("MYGCloudDiskValidityPeriodSheet", owner: nil)?.first as! MYGCloudDiskValidityPeriodSheet
            actionSheet.tapClosePageCompletion = {
                view.rootResponsder().popup.dismissPopup()
            }
            actionSheet.tapIndexCompletion = {(index,obj) in
                view.rootResponsder().popup.dismissPopup()
                completion(index,obj)
            }
            actionSheet.frame = CGRect.init(x: 0, y: 0, width: screenWidth, height: 290 + bottomSafeheight)
            return actionSheet
        }
    }

    /**
     共享-邀请
     */
    static func showInviteSheet(_ view:UIView) {
        view.rootResponsder().popup.bottomSheet(with: true, bgColor: .black.withAlphaComponent(0.43)) {
            let actionSheet = Bundle.main.loadNibNamed("MYGCloudDiskCommonInviteSheet", owner: nil)?.first as! MYGCloudDiskCommonInviteSheet
            actionSheet.tapClosePageCompletion = {
                view.rootResponsder().popup.dismissPopup()
            }
            actionSheet.tapCommonLinkCompletion = {
                view.rootResponsder().popup.dismissPopup()
                let vc = H5ViewController()
                vc.url = MYCloudDiskManager.shared.shareModel.link_open
                view.rootResponsder().navigationController?.pushViewController(vc, animated: true)
            }
            actionSheet.frame = CGRect.init(x: 0, y: 0, width: screenWidth, height: 160 + bottomSafeheight)
            return actionSheet
        }
    }
    
    /**
     共享-新增
     */
    static func showCommonShareAddFileAlert(_ view:UIView,fid:Int) {
        view.rootResponsder().popup.bottomSheet(with: true, bgColor: .black.withAlphaComponent(0.43)) {
            let actionSheet = Bundle.main.loadNibNamed("MYGCloudDiskAddFileSheet", owner: nil)?.first as! MYGCloudDiskAddFileSheet
            actionSheet.fid = fid
            actionSheet.hideShare = true
            actionSheet.tapCloseCompletion = {
                view.rootResponsder().popup.dismissPopup()
            }
            actionSheet.tapCreatFileCompletion = {
                view.rootResponsder().popup.dismissPopup()
                MYGCloudDiskPopManager.showCreatNewFileAlert(view,pid: "\(fid)")

            }
            
//            //共享
//            actionSheet.tapShareCompletion = {
//                view.rootResponsder().popup.dismissPopup()
//                let vc = MYGCloudDiskCommonShareVC()
//                view.rootResponsder().navigationController?.pushViewController(vc, animated: true)
//            }
            actionSheet.frame = CGRect.init(x: 0, y: 0, width: screenWidth, height: 224 + bottomSafeheight)
            return actionSheet
        }
    }
    /*
   上传下载
    */
    static func showDownloadUploadView(_ view:UIView,isFirst:Bool = false) {
       view.rootResponsder().popup.bottomSheet(with: false, bgColor: .black.withAlphaComponent(0.43)) {
           let actionSheet = MYGDownloadManager.downloadUploadView
           actionSheet.tapCloseCompletion = {
               view.rootResponsder().popup.dismissPopup()
           }
           actionSheet.isHidden = isFirst
           actionSheet.frame = UIScreen.main.bounds
           return actionSheet
       }
       if isFirst {
            view.rootResponsder().popup.dismissPopup()

        }
   }
    
    //分享弹窗
    
    
    static func showComonShare(_ view:UIView,meeting_id:String) {
       view.rootResponsder().popup.bottomSheet(with: true, bgColor: .black.withAlphaComponent(0.43)) {
           let actionSheet = Bundle.main.loadNibNamed("MYGAcademicShareView", owner: nil)?.first as! MYGAcademicShareView
           actionSheet.meeting_id = meeting_id
           actionSheet.tapCloseCompletion = {
               view.rootResponsder().popup.dismissPopup()
           }
           actionSheet.frame = CGRect.init(x: 0, y: 0, width: screenWidth, height: 160 + bottomSafeheight)
           return actionSheet
       }
    
   }
    
}

